//
//  AppDelegate.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/7/28.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "AppDelegate.h"
#import "BBLaunchAdMonitor.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

+ (AppDelegate *)shareAppDelegate{
    return (AppDelegate*)[UIApplication sharedApplication].delegate;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [NSThread sleepForTimeInterval:2];//设置启动页面时间
    [self.window makeKeyAndVisible];
    [FLPAYMANAGER fl_registerApp];
    [WXApi registerApp:@"wx844dd1f1217f4c0b"];
 
    // 获取类库的单例变量
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
    // 控制整个功能是否启用
    keyboardManager.enable = YES;
    // 控制点击背景是否收起键盘
    keyboardManager.shouldResignOnTouchOutside = YES;
    // 控制键盘上的工具条文字颜色是否用户自定义
    //    keyboardManager.shouldToolbarUsesTextFieldTintColor = YES;
    // 有多个输入框时，可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框
    //    keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews;
    // 控制是否显示键盘上的工具条
    keyboardManager.enableAutoToolbar = NO;
    // 是否显示占位文字
    //    keyboardManager.shouldShowTextFieldPlaceholder = YES;
    // 设置占位文字的字体
    //    keyboardManager.placeholderFont = [UIFont boldSystemFontOfSize:17];
    // 输入框距离键盘的距离
    //    keyboardManager.keyboardDistanceFromTextField = 10.0f;
    
    //5bb642bcb465f586aa000084
    [[UMSocialManager defaultManager] openLog:YES];

    [[UMSocialManager defaultManager] setUmSocialAppkey:@"5bb642bcb465f586aa000084"];
    
    [self registerUMKey];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    UIViewController *toot = [[UIViewController alloc] init];
    self.window.rootViewController = toot;
    [RequestOperationManager startUp_Success:^(id result) {
        if (DEF_REQ_SUCCESS) {
            NSString * path = [NSString stringWithFormat:@"%@%@",DEF_INTERFACE_WEBVIEWSERVICE,result[@"data"][@"image"]];
            [BBLaunchAdMonitor showAdAtPath:path onView:self.window timeInterval:3 isClick:NO clickBlock:^(BOOL stop) {
               // if (DEF_UID) {
                    [self enterHomePageVC];
              //  }else{
              //      [self enterLogin];
              //  }
            }];
        }
    } failture:^(NSError *error) {

    }];
    
 
    return YES;
}

/** 注册平台 */
- (void)registerUMKey{

    //    setPlaform是要注册的平台
    
    /* 微信聊天 */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx844dd1f1217f4c0b" appSecret:@"c660d669cde7d91831fe2207feaf73f6" redirectURL:nil];
    
    /*QQ*/
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1107827256"  appSecret:@"CEvCntYfLSUhgf7J" redirectURL:@"http://mobile.umeng.com/social"];
    
//
//    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
//    entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
//    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//
//    }
//    [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
}

- (void)enterHomePageVC{
    YYTabbarController *contentTabbar = [[YYTabbarController alloc] init];
    self.window.rootViewController = contentTabbar;
}

- (void)enterLogin{
    //YYLoginViewController * login = [CFUtility getVC:@"" Storyboard:@""];
    YYNavController * login = [[YYNavController alloc] initWithRootViewController:[CFUtility getVC:@"YYLoginViewController" Storyboard:LOGIN]];
    [login setNavigationBarHidden:YES];
    self.window.rootViewController = login;
}
// 支持所有iOS系统
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    //6.3的新的API调用，是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
    if (!result) {
        // 其他如支付等SDK的回调
    }
    return result;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
    //6.3的新的API调用，是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
    BOOL result = [[UMSocialManager defaultManager]  handleOpenURL:url options:options];
    if (!result) {
        // 其他如支付等SDK的回调
         return [FLPAYMANAGER fl_handleUrl:url];
    }
    return result;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
    if (!result) {
        // 其他如支付等SDK的回调
         return [FLPAYMANAGER fl_handleUrl:url];
    }
    return result;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    
    /// Required - 注册 DeviceToken
    [JPUSHService registerDeviceToken:deviceToken];
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
